home *** CD-ROM | disk | FTP | other *** search
/ Aminet 30 / Aminet 30 (1999)(Schatztruhe)[!][Apr 1999].iso / Aminet / util / arc / LZHUtils_src.lha / FixLZH.c < prev    next >
C/C++ Source or Header  |  1997-06-05  |  3KB  |  100 lines

  1. /*************************************************
  2.     FixLZH : Fix an LZH archive (run ScanLZH first!)
  3.     
  4.     Copyright © 1994 Manolis S Pappas.
  5.     All rights reserved.
  6.     
  7.  *************************************************/
  8.  
  9. #include <stdio.h>
  10. #include <stdlib.h>
  11. #include <string.h>
  12. #include <limits.h>
  13.  
  14. #define VERSION "1.1"
  15. #define CLI_VERSION "$VER: FixLZH v1.1"
  16.  
  17. FILE *f1, *f2, *f3;
  18. char name[256], buf[SHRT_MAX];
  19.  
  20. void main(int argc, char *argv[])
  21. {
  22.     unsigned long start;
  23.     long size;
  24.     char *p;
  25.  
  26.     if (argc != 4) {
  27.         printf("FixLZH v%s\n",VERSION);
  28.         printf("Copyright (©) 1994-95, The Xperts Group Inc.\n");
  29.                 printf("All Rights Reserved Worldwide.\n");
  30.                 printf("Author: Manolis S Pappas.\n\n");
  31.         printf("Usage : %s info-file bad-lzh new-lzh\n",argv[0]);
  32.         return;
  33.     }
  34.     strcpy(name, argv[1]);
  35.     f1 = fopen(name, "rt");
  36.     if (f1 == NULL) {
  37.         printf("FixLZH. Copyright © 1994 The Xperts Group. Version %s\n",VERSION);
  38.         printf("Written by Manolis S Pappas. All Rights Reserved.\n");
  39.         printf("\a");
  40.         printf("\nERROR: Info-file '%s' can't open.\n\a", argv[1]);
  41.         return;
  42.     }
  43.     strcpy(name, argv[2]);
  44.     f2 = fopen(name, "rb");
  45.     if (f2 == NULL) {
  46.         strcat(name, ".lzh");
  47.         f2 = fopen(name, "rb");
  48.         if (f2 == NULL) {
  49.             printf("FixLZH. Copyright © 1994 The Xperts Group. Version %s\n",VERSION);
  50.                 printf("Written by Manolis S Pappas. All Rights Reserved.\n");
  51.               printf("\nERROR: Org-lzh '%s' can't open.\n\a\a", argv[2]);
  52.             return;
  53.         }
  54.     }
  55.     strcpy(name, argv[3]);
  56.     if (strchr(name, '.') == NULL) {
  57.         strcat(name, ".lzh");
  58.     }
  59.     if (fopen(name, "rb")) {
  60.         printf("FixLZH. Copyright © 1994 The Xperts Group. Version %s\n",VERSION);
  61.         printf("Written by Manolis S Pappas. All Rights Reserved.\n");
  62.         printf("\nERROR: New-lzh '%s' already exists.\n\a\a", name);
  63.         return;
  64.     }
  65.     f3 = fopen(name, "wb");
  66.     if (f3 == NULL) {
  67.         printf("FixLZH. Copyright © 1994 The Xperts Group. Version %s\n",VERSION);
  68.         printf("Written by Manolis S Pappas. All Rights Reserved.\n");
  69.         printf("\nERROR: New-lzh '%s' can't open.\n\a\a", name);
  70.         return;
  71.     }
  72.     while (fgets(buf, sizeof(buf), f1)) {
  73.         if (*buf == '=') continue;
  74.         start = strtoul(buf, &p, 16);
  75.         size = strtoul(p, &p, 16) - start;
  76.         if (size <= 0) {
  77.             printf("ERROR: Illegal position : %s\n\a", buf);
  78.             continue;
  79.         }
  80.         fseek(f2, start, SEEK_SET);
  81.         while (size) {
  82.             int l;
  83.  
  84.             l = (size > sizeof(buf)) ? sizeof(buf) : size;
  85.             fread(buf, l, 1, f2);
  86.             fwrite(buf, l, 1, f3);
  87.             size -= l;
  88.         }
  89.     }
  90.     putc('\0', f3);
  91.     fclose(f3);
  92.     fclose(f2);
  93.     fclose(f1);
  94. }
  95.  
  96. void do_nothing()
  97. {
  98.         printf("%s",CLI_VERSION);
  99. }
  100.